﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SpinningAnchor : MonoBehaviour {

	public Transform m_instance;
	public float m_spinningSpeed;
	public List<Transform> m_anchorChildren = new List<Transform>();

	// Use this for initialization
	void Start () {
	
	}

	public void Add()
	{
//		GameObject baseAnchor = new GameObject();
//		baseAnchor.transfoarm.parent = transform;
//		baseAnchor.transform.position = 0;
		Transform newInstance = Instantiate(m_instance, Vector3.zero, Quaternion.identity) as Transform;
		newInstance.parent = transform;
		newInstance.localPosition = new Vector3(0, 0, 0);
		m_anchorChildren.Add(newInstance);

		float angle = 360.0f / m_anchorChildren.Count;
		for(int i = 0; i < m_anchorChildren.Count; ++i)
		{
			iTween.RotateTo(m_anchorChildren[i].gameObject, new Vector3(0, 0, angle * i), 0.75f);
		}
	}

	// Update is called once per frame
	void Update () {
		transform.Rotate(new Vector3(0, 0, 1), Time.deltaTime * m_spinningSpeed);
	}
}
